package definite.Guide.Book.CoreSwingComponent.JToolTipClass;

import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolTip;
import javax.swing.border.EmptyBorder;

public class SimpleToolTip extends JFrame {

	private JPanel contentPane;
	private JButton btnNewButton;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SimpleToolTip frame = new SimpleToolTip();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SimpleToolTip() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		btnNewButton = new JButton("New button") {
			JToolTip tip;

			public JToolTip createToolTip() {
				tip = super.createToolTip();
				tip.setBackground(Color.YELLOW);
				tip.setForeground(Color.RED);
				// tip.setTipText("Hello World");
				return tip;
			}

			public boolean contains(int x, int y) {
				if (x < 50) {
					setToolTipText("Got Green Eggs?");
				} else {
					setToolTipText("Got Ham?");
				}
				return super.contains(x, y);
			}

		};

		btnNewButton.setBounds(35, 57, 149, 47);
		contentPane.add(btnNewButton);
	}
}
